﻿package styles 
{
	import com.anttikupila.revolt.effects.Tint;
	import flash.display.DisplayObject;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import gs.easing.Cubic;
	import util.FilterMaster;
	/**
	 * Стиль поведения кнопки-обертки
	 * @author Kasoi
	 */
	public class ButtonStyle
	{
		
		////////////////////////////////////////////////////////////////////
		// Public properties
		////////////////////////////////////////////////////////////////////
		
		public function get actionAnimation() : Function 
		{
			return this._actionAnimation;
		}
		
		public function set actionAnimation(value: Function) : void 
		{
			this._actionAnimation = value;
		}
		
		public function get disableAnimation() : Function 
		{
			return this._disableAnimation;
		}
		
		public function set disableAnimation(value: Function) : void 
		{
			this._disableAnimation = value;
		}
		
		
		
		public var hoverTime: Number = 0.5;
		
		public var actionTime: Number = 0.2;
		
		public var disableTime: Number = 0.4;
		
		public var hoverEasing: Function = Cubic.easeOut;
		
		public var actionEaseing: Function = Cubic.easeOut;
		
		public var disableEasing: Function = Cubic.easeOut;
		
		public var hoverAnimation: Function;
		
		////////////////////////////////////////////////////////////////////
		// Private properties
		////////////////////////////////////////////////////////////////////
		
		private var _hoverAnimation: Function;
		
		private var _actionAnimation: Function;
		
		private var _disableAnimation: Function;
		
		////////////////////////////////////////////////////////////////////
		// Public methods
		////////////////////////////////////////////////////////////////////
		
		public function ButtonStyle() 
		{
			this.hoverAnimation = this.defaultHoverAnimation;
			this.actionAnimation = this.defaultActionAnimation;
			this.disableAnimation = this.defaultDisableAnimation;
		}
		
		public function defaultHoverAnimation(image: DisplayObject, value: Number = 0) : void 
		{
			FilterMaster.brightness(image, -value * 0.9);
			if (value == 0) image.filters = [];
			FilterMaster.blackAndWhite(image, value);
		}
		
		public function defaultActionAnimation(image: DisplayObject, value: Number = 0) : void 
		{
			if (value == 0) 
			{
				return;
			}
			FilterMaster.blackAndWhite(image, 1);
			FilterMaster.brightness(image, -0.9 -value * 0.3);
		}
		
		public function defaultDisableAnimation(image: DisplayObject, value: Number = 0) : void 
		{
			var blur: BlurFilter = new BlurFilter(2 * (value), 2 * (value), 2);
			image.filters = [blur];
			image.alpha = 1 - value * 0.5;
			if (value == 0) image.filters = [];
		}
	}

}